package com.igeek.compus.test.notice.service.impl;

import com.igeek.compus.test.menu.entity.Menu;
import com.igeek.compus.test.notice.dao.NoticeDao;
import com.igeek.compus.test.notice.entity.Notice;
import com.igeek.compus.test.notice.service.NoticeService;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeDao noticeDao;

    @Override
    public List<Notice> getNoticeListByPage(Notice notice) {
        return noticeDao.getNoticeListByPage(notice);
    }

    @Override
    public int getNoticeListCount(Notice notice) {
        return noticeDao.getNoticeListCount(notice);
    }

    @Override
    public Notice getNoticeInfoById(Integer id) {
        return noticeDao.getNoticeInfoById(id);
    }

    @Override
    public int deleteNoticeById(Notice notice) {
        return noticeDao.deleteNoticeById(notice);
    }

    @Override
    public int deleteNoticeList(List<String> noticeIdList) {
        return noticeDao.deleteNoticeList(noticeIdList);
    }

    @Override
    public int addNotice(Notice notice) {
        return noticeDao.addNotice(notice);
    }

    @Override
    public int updateNotice(Notice notice) {
        return noticeDao.updateNotice(notice);
    }

    @Override
    public HSSFWorkbook noticeExport(String[] titles, List<Notice> noticeList) {
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet();

//        CellStyle style = wb.createCellStyle();
////        style.setAlignment(HorizontalAlignment.CENTER); // 创建一个居中格式
//        style.setFillForegroundColor(HSSFColor.HSSFColorPredefined.GREEN.getIndex());
//        style.setBorderBottom(BorderStyle.THIN);
//        style.setBorderLeft(BorderStyle.THIN);
//        style.setBorderRight(BorderStyle.THIN);
//        style.setBorderTop(BorderStyle.THIN);

        HSSFRow head = sheet.createRow(0);
        for(int i = 0; i < titles.length; i++) {
            HSSFCell cell = head.createCell(i);
            cell.setCellValue(titles[i]);
        }

        for(int i = 0; i < noticeList.size(); i++) {
            HSSFRow row = sheet.createRow(i + 2);
            row.setHeight((short) 350);
            Notice notice = noticeList.get(i);

            HSSFCell cell1 = row.createCell(0);
//            cell1.setCellStyle(style);
            cell1.setCellValue(notice.getTitle());

            HSSFCell cell2 = row.createCell(1);
            cell2.setCellValue(notice.getContent());

            HSSFCell cell3 = row.createCell(2);
            cell3.setCellValue(notice.getPublisher());

            HSSFCell cell4 = row.createCell(3);
            cell4.setCellValue(notice.getCreateTime());
        }

        return wb;
    }
}
